import request from '@/utils/request'
import Qs from 'qs'

/**
 * 查询任务列表
 * @param {*} pageNum
 * @param {*} pageSize
 * @param {任务名称} jobName
 * @param {etl系统} system
 * @param {用户名} userName
 * @returns
 */
export function etlJobList(pageNum, pageSize, queryform) {
  return request({
    url: '/job/etlJobList',
    method: 'post',
    headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
    transformRequest: [function(data) { return Qs.stringify(data) }],
    data: {
      pageNum: pageNum,
      pageSize: pageSize,
      system: queryform.system,
      jobName: queryform.jobName,
      userName: queryform.userName,
      jobType: queryform.jobType,
      enable: queryform.enable,
      status: queryform.status
     
    }
  })
}

/**
 * 添加作业
 * @param {job实体}} para
 * @returns
 */
export function addJob (data) {
  return request({
    // url: '/job/addJob',
    url: '/job/addJobBySql',
    method: 'post',
    data: data,
    headers: {
      'Content-Type': 'application/json'
    }
  })
}


/**
 * 停止作业
 * @param {job实体}} para
 * @returns
 */

export function stopEtlJob (para) {
    return request({
      url: '/job/stopEtlJob',
      data: para,
      method: 'post',
      headers: {
        'Content-Type': 'application/json'
      }
    })
  }

  /**
 * 启动作业
 * @param {job实体}} para
 * @returns
 */

export function startEtlJob (para) {
    return request({
      url: '/job/startEtlJob',
      data: para,
      method: 'post',
      headers: {
        'Content-Type': 'application/json'
      }
    })
  }


  
/**
 * 删除作业
 * @param {job实体}} para
 * @returns
 */
  export function deleteEtlJob (para) {
    console.log(para)
    return request({
      url: '/job/deleteEtlJob',
      data: para,
      method: 'post',
      headers: {
        'Content-Type': 'application/json'
      }
    })
  }

//查看系统
export function findSystems (userName) {
    return request({
      url: '/job/findSystems?userName=' + userName,
      method: 'post'
    })
  }
  
  
  export function findJobBySystemName (systemName) {
    return request({
      url: '/job/findJobBySystemName?systemName=' + systemName,
      method: 'post'
    })
  }


 //条件查询命令实体
export function findJobCommandById (etlSystem,etlJob) {
  return request({
    url: '/jobCommand/findJobCommandById?etlSystem=' + etlSystem+'&etlJob='+etlJob,
    method: 'post'
  })
}

//条件查询时间触发实体

export function findTimeTriggerById (etlSystem,etlJob) {
  return request({
    url: '/timeTrigger/findTimeTriggerById?etlSystem=' + etlSystem+'&etlJob='+etlJob,
    method: 'post'
  })
}

export function findDependenceJob (systemJobName) {
  return request({
    url: '/jobDependency/findDependenceJob?systemJobName=' + systemJobName,
    method: 'post'
  })
}


